
*********************************************************************************
** PRELIMINARIES
*********************************************************************************

********************************************************************
** WAVE 1 POST-HARVEST DATA
********************************************************************

** Roster Information
use "$dir/rawdata/LSMS Nigeria/2010/Post Harvest Wave 1/Household/sect1_harvestw1.dta", clear // ROSTER
count
local samplesize=`r(N)'
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2010/Post Harvest Wave 1/Household/sect2a_harvestw1.dta", gen(merge_sec2a) assert(master matched) // EDUCATION, A
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2010/Post Harvest Wave 1/Household/sect2b_harvestw1.dta", gen(merge_sec2b) assert(master matched) // EDUCATION, B
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2010/Post Harvest Wave 1/Household/sect3a_harvestw1.dta", gen(merge_sec3a) assert(master matched) // LABOR, A
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2010/Post Harvest Wave 1/Household/sect3b_harvestw1.dta", gen(merge_sec3b) assert(master matched) // LABOR, B
merge 1:1 hhid indiv using "$dir/rawdata/LSMS Nigeria/2010/Post Harvest Wave 1/Household/sect4a_harvestw1.dta", gen(merge_sec4a) assert(master matched) // HEALTH

** Still in HH 
gen w1h_inhh=s1q19!=2

** Household size
gen temp=1 if w1h_inhh==1
bys hhid: egen w1h_hh_size=total(temp)
drop temp

** Number of children 12 or younger
gen temp=1 if s1q4<=12 & w1h_inhh==1
bys hhid: egen w1h_hh_under12=total(temp)
drop temp

** Number of youth 18 or younger
gen temp=1 if s1q4<=18 & w1h_inhh==1
bys hhid: egen w1h_hh_under18=total(temp)
drop temp

** Number of adults 60 or older
gen temp=1 if s1q4>=60 & !missing(s1q4) & s1q4!=999 & w1h_inhh==1
bys hhid: egen w1h_hh_over60=total(temp)
drop temp

** Adults 12 to 60
gen temp=1 if s1q4>12 & s1q4<60 & !missing(s1q4) & s1q4!=999 & w1h_inhh==1
bys hhid: egen w1h_hh_12to60=total(temp)
drop temp

** Marital status
gen w1h_married=(s1q7==1 | s1q7==2) if !missing(s1q7)
gen w1h_married_monog=s1q7==1 if !missing(s1q7)
gen w1h_married_polyg=s1q7==2 if !missing(s1q7)

** Female
gen w1h_female=(s1q2==2) if !missing(s1q2)

** Age
gen w1h_age=s1q4
replace w1h_age=. if w1h_age==999

** Age of spouse
sum indiv 
forvalues x=1/`r(max)' {
	gen age_person`x'_temp=s1q4 if indiv==`x' & !missing(s1q4)
	bys hhid: egen age_person`x'=max(age_person`x'_temp)
	drop age_person`x'_temp
}

** Average age of others in the household
sum indiv 
forvalues x=1/`r(max)' {
	replace age_person`x'=. if indiv==`x'
}
egen w1h_hh_avgage=rowmean(age_person*)

** Spouse age
sum indiv
forvalues x=1/`r(max)' {
	replace age_person`x'=. if s1q12!=`x'
}
egen w1h_spouse_age=rowmean(age_person*)

** Age gap
gen w1h_spouse_agegap=w1h_age-w1h_spouse_age

** Birth day
gen w1h_birthday=mdy(s1q6_month,s1q6_day,s1q6_year)
format w1h_birthday %td

** Birth year
gen w1h_birthyear=s1q6_year
recode w1h_birthyear 9999=. 9998=.

** Birth year: Fill in the gaps with imputed birth year (assuming today is the respondent's birthday)
replace w1h_birthyear=2011-w1h_age if missing(w1h_birthyear)

** Highest education of individual
gen w1h_educ=s2aq9
replace w1h_educ=0 if s2aq6==2 // Never attended school
label values w1h_educ s2aq9
replace w1h_educ=. if s2aq9==98

** Still in school
gen w1h_inschool=(s2bq1==1) if !missing(s2bq1)

** Literate
gen w1h_literate=(s2aq5==1) if !missing(s2aq5)

** Worked for a non-HH member
gen w1h_work_outsideHH=s3aq1==1 if !missing(s3aq1)

** Worked in agriculture for a HH member
gen w1h_work_agHH=s3aq2==1 if !missing(s3aq2)

** Worked in HH business
gen w1h_work_bizHH=s3aq3==1 if !missing(s3aq3)

** Any work in last 7 days (agriculture, for non-HH member, own account/business)
gen w1h_worked_last7days=0
replace w1h_worked_last7days=1 if s3aq1==1
replace w1h_worked_last7days=1 if s3aq2==1 
replace w1h_worked_last7days=1 if s3aq3==1
replace w1h_worked_last7days=. if missing(s3aq1) & missing(s3aq2) & missing(s3aq3)

** Hours worked in last 7 days
egen w1h_work_hrs=rowtotal(s3aq15 s3aq27)
replace w1h_work_hrs=. if missing(w1h_worked_last7days)

** Works in agriculture
gen w1h_work_agri=(s3aq23==1 | s3aq11==1) if (!missing(s3aq23) | !missing(s3aq11))
replace w1h_work_agri=0 if w1h_worked_last7days==0

** Industry of occupation (NOTE: Almost no relevant data here)
gen w1h_occ=s1q42
label values w1h_occ s1q42

** Highest education of biological father
gen w1h_father_educ=s1q26
label values w1h_father_educ s1q26
replace w1h_father_educ=. if w1h_father_educ==98

** Industry of occupation of biological father
gen w1h_father_occ=s1q27
label values w1h_father_occ s1q27

** Highest education of biological mother
gen w1h_mother_educ=s1q31
label values w1h_mother_educ s1q31
replace w1h_mother_educ=. if w1h_mother_educ==98

** Industry of occupation of biological mother
gen w1h_mother_occ=s1q32
label values w1h_mother_occ s1q32

** ID of father and mother (for linking)
gen w1h_father_id=s1q24 
gen w1h_mother_id=s1q29

** GEOGRAPHIC INFORMATION
gen w1h_geo_urban=(sector==1) if !missing(sector)
gen w1h_geo_state=state
gen w1h_geo_lga=lga
replace w1h_geo_lga=s1q36b if !missing(s1q36b) // LGA code for where the HH member moved
label var w1h_geo_urban "Urban residence"
label var w1h_geo_state "State of residence"
label var w1h_geo_lga "LGA of residence"

** DISABILITIES

	** Difficulty seeing
		tab1 s4aq23, nol
		tab1 s4aq23
		gen w1h_diff_seei=1 if inlist(s4aq23, 2, 3, 4) 
		replace w1h_diff_seei=0 if inlist(s4aq23, 1)
		replace w1h_diff_seei=. if inlist(s4aq23, .)
		tab1 w1h_diff_seei

	** Difficulty hearing
		tab1 s4aq25, nol
		tab1 s4aq25
		gen w1h_diff_hear=1 if inlist(s4aq25, 2, 3, 4) 
		replace w1h_diff_hear=0 if inlist(s4aq25, 1)
		replace w1h_diff_hear=. if inlist(s4aq25, .)
		tab1 w1h_diff_hear

	** Difficulty walking or climbing stairs	
		tab1 s4aq27, nol
		tab1 s4aq27
		gen w1h_diff_walk_clim=1 if inlist(s4aq27, 2, 3, 4) 
		replace w1h_diff_walk_clim=0 if inlist(s4aq27, 1)
		replace w1h_diff_walk_clim=. if inlist(s4aq27, .)
		tab1 w1h_diff_walk_clim

	** Difficulty remembering or concentrating
		tab1 s4aq29, nol
		tab1 s4aq29
		gen w1h_diff_reme=1 if inlist(s4aq29, 2, 3, 4) 
		replace w1h_diff_reme=0 if inlist(s4aq29,1)
		replace w1h_diff_reme=. if inlist(s4aq29, .)
		tab1 w1h_diff_reme

	** Difficulty with self-care
		tab1 s4aq31, nol
		tab1 s4aq31
		gen w1h_diff_self_care=1 if inlist(s4aq31, 2, 3, 4)
		replace w1h_diff_self_care=0 if inlist(s4aq31, 1)
		replace w1h_diff_self_care=. if inlist(s4aq31, .)
		tab1 w1h_diff_self_care

	** Difficulty communicating
		tab1 s4aq33, nol
		tab1 s4aq33
		gen w1h_diff_comm=1 if inlist(s4aq33, 2, 3, 4) 
		replace w1h_diff_comm=0 if inlist(s4aq33, 1)
		replace w1h_diff_comm=. if inlist(s4aq33, .)
		tab1 w1h_diff_comm

********************************************************************
********************************************************************

** HEALTH 

	** Any illness or injury during the last 4 weeks
		gen w1h_ill_inj=(s4aq3==1 | s4aq3==2) if !missing(s4aq3)

	** Had to stop usual activity in the past 4 weeks
		gen w1h_ill_inj_stopactivity=(s4aq4==1) if !missing(s4aq4)
		replace w1h_ill_inj_stopactivity=0 if w1h_ill_inj==0

merge m:1 hhid using "$dir/rawdata/LSMS Nigeria/2010/cons_agg_wave1_visit1.dta", keep(master matched) nogen
ren hhsize w1h_hhsize_fromcons

keep hhid indiv w1*
order hhid indiv w1h_geo*
save "$dir/data/NGA_w1h_individual.dta", replace
